<%@page import="com.qf.fanwang.utils.Tools"%>
<%@ page language="java" contentType="text/html; charset=utf-8"
	pageEncoding="utf-8"%>
<%@taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<%@taglib uri="http://java.sun.com/jsp/jstl/fmt" prefix="f"%>
<%@taglib uri="http://java.sun.com/jsp/jstl/sql" prefix="s"%>
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<link type="text/css" rel="stylesheet" href="static/css/head.css" />
<title>Insert title here</title>
</head>
<body>
<c:if test="${empty(sessionScope.user)}"><a href="user?action=login">登录</a></c:if><!-- 如果为用户为空显示登录 -->
	<c:if test="${!empty(sessionScope.user) }">${user.uname}</c:if><!-- 不为空显示用户名 -->
	&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<a href="user?action=logout">注销</a>
	&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<a href="cart">查看</a>
	<%@include file="head.jsp"%>
	<div id="lay2">
		<table border="1" align="center">
			<tr>
				<td>商品编号</td>
				<td>商品名</td>
				<td>生产日期</td>
				<td>图片</td>
				<td>价格</td>
				<td>级别</td>
				<td>描述</td>
				<td>商品类别</td>
				<td colspan="3">操作</td>
			</tr>
			<c:forEach items="${requestScope.glist }" var="goods">
				<tr>
					<td>${goods.getGid()}</td>
					<td>${goods.getGname()}</td>
					<td><f:formatDate value="${goods.getPubdate()}"
							pattern="yyyy-MM-dd" /></td>
					<td><img width="80px" height="80px" src="${goods.getPic()}" /></td>
					<td>${goods.getPrice() }</td>
					<td>${goods.getStar() }</td>
					<td>${goods.getInfo() }</td>
					 <td><select name="good">
							<c:forEach items="${clist }" var="cl">
								<option
									<c:if test="${cl.gid==goods.typeid}">selected="selected"</c:if>
									value="${cl.gid }">${cl.gname }</option>
							</c:forEach>
					</select></td> 
					<%-- <td><a href="goods?action=delete&id=${goods.gid}">删除</a></td> --%>
					<td colspan="3"><a href="goods?action=selectOne&id=${goods.gid}">查看商品详情</a></td>
					<!-- <td><a href="goods?action=selectOne">添加</a></td> -->
				</tr>
			</c:forEach>
			<tr align="center"> 
				<td colspan="11"><a
					href="goods?action=selectLike&page=1&search=${search}">首页||</a> <a
					href="goods?action=selectLike&page=${pb.page-1<1?1:(pb.page-1)}&search=${search } ">上页||</a>
					<%-- <c:choose>
					<c:when test="${pb.page+1>pb.pageNum}">
						<a href="goods?action=selectLike&page=${pb.pageNum} &search=${search} ">下页</a>
					</c:when>
					<c:otherwise>
						<a href="goods?action=selectLike&page=${pb.page+1}&search=${search} ">下页</a>
					</c:otherwise>
				</c:choose> --%>
				
				<c:if test="${pb.page+1<=pb.pageNum}">
						<a href="goods?action=selectLike&page=${pb.page+1}&search=${search}">下页||</a>
					</c:if>
				<a href="goods?action=selectLike&page=${pb.pageNum}&search=${search} ">末页||</a>
					第${pb.page}页||共${pb.pageNum}页||每页显示${pb.rowsPerPage}条数据||共${pb.rowsNum}条数据
				</td>
			</tr>
			<tr align="center">
				<td colspan="11"><c:choose>
						<c:when test="${pb.pageNum<3}">
							<c:forEach begin="1" step="1" end="${pb.pageNum }" var="p">
								<c:if test="${p==pb.page}">${p}</c:if>
								<c:if test="${p!=pb.page }">
									<a href="goods?action=selectLike&page=${p}&search=${search } ">${p}</a>
								</c:if>
							</c:forEach>
						</c:when>
						<c:otherwise>
							<c:choose>
								<c:when test="${pb.page==1 }">
									<c:forEach begin="1" step="1" end="3" var="p">
										<c:if test="${p==pb.page}">${p}</c:if>
										<c:if test="${p!=pb.page }">
											<a href="goods?action=selectLike&page=${p}&search=${search } ">${p}</a>
										</c:if>
									</c:forEach>
								</c:when>
								<c:when test="${pb.page==pb.pageNum }">
									<c:forEach begin="${pb.page-2 }" step="1" end="${pb.pageNum }"
										var="p">
										<c:if test="${p==pb.page}">${p}</c:if>
										<c:if test="${p!=pb.page }">
											<a href="goods?action=selectLike&page=${p}&search=${search } ">${p}</a>
										</c:if>
									</c:forEach>
								</c:when>
								<c:otherwise>
									<c:forEach begin="${pb.page-1 }" step="1" end="${pb.page+1 }"
										var="p">
										<c:if test="${p==pb.page}">${p}</c:if>
										<c:if test="${p!=pb.page }">
											<a href="goods?action=selectLike&page=${p}&search=${search } ">${p}</a>
										</c:if>
									</c:forEach>
								</c:otherwise>
							</c:choose>
						</c:otherwise>
					</c:choose> <%--  <c:forEach begin="1" end="${pb.pageNum}" var="p">
					<c:choose>
						<c:when test="${p==pb.page}">${p}</c:when>
						<c:otherwise>
							<a href="goods?action=selectAll&page=${p}">${p}</a>
						</c:otherwise>
					</c:choose>
				</c:forEach> --%>
			</tr>
		</table>
	</div>
</body>
</html>